/*
* © 2010 Autodata Solutions Company. All Rights Reserved
* This source code is the confidential and proprietary information of Autodata Solutions Company.
* The user shall not, in whole or in part, copy, publish, disclose or make any use of this source code
* without the prior written consent of Autodata Solutions Company.
*/
Ext.ns('net.autodata.compare.plugins');
(function() {
    var EVENTS = net.autodata.EventBus.EVENTS;

    /**
    * This plugin is used to bind the CompetitorToolbar to the events of the GridPanal.
    * This will keep the CompetitorToolbar always insync with the display of the CompareVehiclesPanel.
    * @class CompetitorToolbarGridConnector
    * @extends Ext.util.Observable
    * @namespace net.autodata.compare.plugins
    */
    var Plugin = Ext.extend(Ext.util.Observable, {
        /**
        * @property toolbar
        * @type net.autodata.compare.CompetitorToolbar
        */
        toolbar: undefined,

        constructor: function(cfg) {
            cfg = cfg || {};

            Ext.apply(this, cfg);

            if (this.toolbar === undefined) {
                throw 'toolbar is a required parameter';
            }

            Plugin.superclass.constructor.apply(this, arguments);
        },

        /**
        * @method init
        * @param {Ext.GridPanel} grid
        */
        init: function(grid) {
            this.grid = grid;
            this.toolbar.on('vehicleselected', this.grid.onVehicleSelected, this.grid);
        },


        /**
        * Used to clean up all event bindings made by this plugin
        * @private
        */
        onDestroy: function() {
            this.toolbar.un('vehicleselected', this.grid.onVehicleSelected, this.grid);
        }

    });

    net.autodata.compare.plugins.CompetitorToolbarGridConnector = Plugin;

})();